// Package database @program: account
//@author: edte
//@create: 2021-12-28 09:56
package database

import (
	log2 "account/log"
	"account/tools"
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"strconv"
)

func USerQueryData(ctx context.Context, userId int) (user string, err error) {
	/*rdb := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
		//PoolSize: 500, // 连接池大小
	})*/

	redisPath := tools.GetEnv("REDIS_PATH", "localhost:6379")
	redisPD := tools.GetEnv("REDIS_PASSWORD", "")
	rdb := redis.NewClient(&redis.Options{
		Addr:     redisPath,
		Password: redisPD, // no password set
		DB:       0,       // use default DB
		//PoolSize: 500, // 连接池大小
	})

	users, err := rdb.Get(ctx, strconv.Itoa(userId)).Result()
	if err != nil {
		writeLog, err2 := log2.WriteLog(context.Background(), "account", "USerQueryData", strconv.Itoa(userId), "Warring", err.Error())
		if writeLog == 200 {
			fmt.Println("成功写入日志")
		}
		if err2 != nil {
			fmt.Println("写入日志失败")
		}
		return "", err
	}
	return users, err
}
